import random


def guess_number_game():
    # 初始化金币数
    gold = 5000
    while gold >= 500:
        # 随机生成幸运数字
        lucky_number = random.randint(1, 100)
        while True:
            # 用户输入猜测的数字
            guess = int(input("请输入你猜测的数字（1-100）："))
            # 扣除金币数
            gold -= 500
            # 判断金币是否够
            if gold < 500:
                print("您的金币不足，结束游戏")
                break
            if guess > lucky_number:
                print("大了")
            elif guess < lucky_number:
                print("小了")
            else:
                # 奖励金币数
                gold += 3000
                print(f"恭喜你猜中了，本轮幸运数字为：{lucky_number}，奖励3000金币！")
                print(f"当前金币数为：{gold}")
                # 询问玩家是否继续游戏
                play_again = input("是否继续游戏？(y/n)")
                if play_again == 'n':
                    print("游戏结束。")
                    return
                break


if __name__ == '__main__':
    guess_number_game()
